package com.ruoyi.puyu.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.puyu.domain.PuyuCoachSalary;
import com.ruoyi.puyu.service.IPuyuCoachSalaryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 教练薪资Controller
 * 
 * @author wusongwen
 * @date 2024-05-01
 */
@RestController
@RequestMapping("/puyu/coachsalary")
public class PuyuCoachSalaryController extends BaseController
{
    @Autowired
    private IPuyuCoachSalaryService puyuCoachSalaryService;

    /**
     * 查询教练薪资列表
     */
    @PreAuthorize("@ss.hasPermi('puyu:coachsalary:list')")
    @GetMapping("/list")
    public TableDataInfo list(PuyuCoachSalary puyuCoachSalary)
    {
        puyuCoachSalary.setDelFlag("0");
        // 教练只能看自己的薪资
        boolean bolRole = SecurityUtils.hasRole(UserConstants.ROLE_COACH);
        if(bolRole) {
            puyuCoachSalary.setUserId(SecurityUtils.getUserId());
        }
        bolRole = SecurityUtils.hasRole(UserConstants.ROLE_MANAGER)
                || SecurityUtils.hasRole(UserConstants.ROLE_ADMIN);
        if(bolRole) {
            puyuCoachSalary.setUserId(null);
        }
        startPage();
        List<PuyuCoachSalary> list = puyuCoachSalaryService.selectPuyuCoachSalaryList(puyuCoachSalary);
        return getDataTable(list);
    }

    /**
     * 导出教练薪资列表
     */
    @PreAuthorize("@ss.hasPermi('puyu:coachsalary:export')")
    @Log(title = "教练薪资", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PuyuCoachSalary puyuCoachSalary)
    {
        List<PuyuCoachSalary> list = puyuCoachSalaryService.selectPuyuCoachSalaryList(puyuCoachSalary);
        ExcelUtil<PuyuCoachSalary> util = new ExcelUtil<PuyuCoachSalary>(PuyuCoachSalary.class);
        util.exportExcel(response, list, "教练薪资数据");
    }

    /**
     * 获取教练薪资详细信息
     */
    @PreAuthorize("@ss.hasPermi('puyu:coachsalary:query')")
    @GetMapping(value = "/{coachSalaryId}")
    public AjaxResult getInfo(@PathVariable("coachSalaryId") Long coachSalaryId)
    {
        return success(puyuCoachSalaryService.selectPuyuCoachSalaryByCoachSalaryId(coachSalaryId));
    }

    /**
     * 新增教练薪资
     */
    @PreAuthorize("@ss.hasPermi('puyu:coachsalary:add')")
    @Log(title = "教练薪资", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PuyuCoachSalary puyuCoachSalary)
    {
        return toAjax(puyuCoachSalaryService.insertPuyuCoachSalary(puyuCoachSalary));
    }

    /**
     * 修改教练薪资
     */
    @PreAuthorize("@ss.hasPermi('puyu:coachsalary:edit')")
    @Log(title = "教练薪资", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PuyuCoachSalary puyuCoachSalary)
    {
        return toAjax(puyuCoachSalaryService.updatePuyuCoachSalary(puyuCoachSalary));
    }

    /**
     * 删除教练薪资
     */
    @PreAuthorize("@ss.hasPermi('puyu:coachsalary:remove')")
    @Log(title = "教练薪资", businessType = BusinessType.DELETE)
	@DeleteMapping("/{coachSalaryIds}")
    public AjaxResult remove(@PathVariable Long[] coachSalaryIds)
    {
        return toAjax(puyuCoachSalaryService.deletePuyuCoachSalaryByCoachSalaryIds(coachSalaryIds));
    }
}
